/**
 * Copyright (c) 2019-2029, wwww.kiwipeach.cn (liuburu@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cn.kiwipeach.blog.exception;

import cn.kiwipeach.blog.base.AjaxResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 描述：重写系统404默认行为
 *
 * @author kiwipeach
 * @since 2.0
 */
@Controller
@RequestMapping("error")
@Slf4j
public class Error404Controller {

    @RequestMapping(value = "404")
    @ResponseBody
    public AjaxResponse<Integer> errorResponse() {
        return AjaxResponse.fail("-PAGE_NOT_FOUND", "找不到页面");
    }

    //@RequestMapping(value = "404", produces = MediaType.TEXT_HTML_VALUE)
    //public String errorHtml(HttpServletRequest request) {
    //    // 404页面将会转发到系统默认首页，配合Vue的处理路由转发404问题
    //    log.warn("404页面转发地址：{}", request.getRequestURL());
    //    return "forward:" + request.getSession().getServletContext().getContextPath();
    //}
}
